package com.qmunit.testexample;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;


public class Person
{
	Date birthdate;
	
	//Excetion f�r Geb. in Zukunft
	/**
	 * Returns the Age of this Person
	 * @return
	 */
	public int getAge()
	{
		if (birthdate == null)
			throw new IllegalArgumentException("Date can not be empty");
		else
		{
			Calendar now = getCurrentCalendar();
			Calendar dob = Calendar.getInstance();
			dob.setTime(birthdate);

			if(dob.after(now))
			{
				throw new IllegalArgumentException("Date of birth is in the future.");
			}
			
			int age = now.get(Calendar.YEAR) - dob.get(Calendar.YEAR);
				

			return (dob.get(Calendar.MONTH) > now.get(Calendar.MONTH))? age-=1 : (now.get(Calendar.MONTH) == dob.get(Calendar.MONTH)) 
					? ((dob.get(Calendar.DAY_OF_MONTH) > now.get(Calendar.DAY_OF_MONTH)) ? age-=1 : age ) : age;

		}
	}
	
	/**
	 * Returns the Current Date
	 * @return CurrentDate
	 */
	public Calendar getCurrentCalendar()
	{
		return Calendar.getInstance();
	}
	
	
	/**
	 * Sets the Birth Date
	 * @param aBirthDate
	 */
	public void setBirthDate(int year, int month, int day)
	{
		this.birthdate = new GregorianCalendar(year, month, day).getTime();
	}
	
	public void setBirthDate(Date d)
	{
		this.birthdate = d;
	}
	
}
